package exercises.day05.pt02.fileio;

import java.io.*;

public class FileIoDemo {

    public static void main(String[] args) {

        // Write to a file
        try {
            File file = new File("Q:\\hello.txt");
            FileWriter writer = new FileWriter(file);
            writer.write("hello world~!");
            writer.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        new FileIoDemo().read();

    }

    public void read() {
        try {
            File file = new File("Q:\\hello.txt");
            FileReader reader = new FileReader(file);
            BufferedReader bufferedReader = new BufferedReader(reader);
            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                //or do something about the content
                System.out.println(line);
            }
            bufferedReader.close();

        } catch (IOException ioex) {
            ioex.printStackTrace();
        }

    }
}